package com.summer.NIO;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.DatagramChannel;

public class DatagramChannelCase1 {

	public static void main(String[] args) throws IOException {
		DatagramChannel channel = DatagramChannel.open();
		channel.socket().bind(new InetSocketAddress(9999));
		
		ByteBuffer buf = ByteBuffer.allocate(1024);
		while(true){
			buf.clear();
			channel.receive(buf);
	
			buf.flip();
			byte[] readByte = new byte[buf.limit()];
			buf.get(readByte, 0, readByte.length);
			
			System.out.println("body:"+new String(readByte));
		}
		
	}
	
}
